<?php

namespace IDock\Insurance\TPIC\Response;

use IDock\Http\Response;
use IDock\Insurance\TPIC\Response\AllTPICResponse;
use IDock\Printer\NonCar\NonCarProductListPrinter;
use IDock\Printer\NonCar\NonCarProductPrinter;
use IDock\Printer\NonCar\NonCarSubCoveragePrinter;
use IDock\Printer\UnderwritingRecallPrinter;

class NonCarProductListResponse extends AllTPICResponse
{

    private $seat5 = '[{"productCode":"C05","productName":"太平驾多保体验版（5座及以下）","productType":"驾意险","productDesc":"","planCode":"C05P150","planName":"太平驾多保体验版（5座及以下）","discount":"","maxQuantity":"1","unitAmount":"1558200","premium":"288","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"200000","premium":"70","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"50000","premium":"50","rate":0,"argc":[]},{"subName":"驾乘意外住院津贴","subCode":"ZR000311","amount":"5400","premium":"16","rate":0,"argc":[]},{"subName":"节假日意外伤害保险加倍","subCode":"ZR005930","amount":"200000","premium":"40","rate":0,"argc":[]},{"subName":"个人行李损失责任","subCode":"ZR005920","amount":"2000","premium":"28","rate":0.01,"argc":[]},{"subName":"房屋-火灾、爆炸损失","subCode":"ZR005950","amount":"1000000","premium":"59","rate":0,"argc":[]},{"subName":"室内装潢及室内附属设施-火灾、爆炸损失","subCode":"ZR005951","amount":"100000","premium":"22","rate":0,"argc":[]},{"subName":"个人出行不便责任","subCode":"ZR005478","amount":"800","premium":"3","rate":0,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"太平驾多保基础版（5座及以下）","productType":"驾意险","productDesc":"","planCode":"C05P153","planName":"太平驾多保基础版（5座及以下）","discount":"","maxQuantity":"1","unitAmount":"1818000","premium":"388","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"300000","premium":"99","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"100000","premium":"84","rate":0,"argc":[]},{"subName":"驾乘意外住院津贴","subCode":"ZR000311","amount":"9000","premium":"29","rate":0,"argc":[]},{"subName":"节假日意外伤害保险加倍","subCode":"ZR005930","amount":"300000","premium":"49","rate":0,"argc":[]},{"subName":"房屋-火灾、爆炸损失","subCode":"ZR005950","amount":"1000000","premium":"59","rate":0,"argc":[]},{"subName":"室内装潢及室内附属设施-火灾、爆炸损失","subCode":"ZR005951","amount":"100000","premium":"22","rate":0,"argc":[]},{"subName":"个人出行不便责任","subCode":"ZR005478","amount":"1000","premium":"4","rate":0,"argc":[]},{"subName":"拦车抢劫财物损失","subCode":"ZR005468","amount":"5000","premium":"7","rate":0,"argc":[]},{"subName":"个人行李损失责任","subCode":"ZR005920","amount":"3000","premium":"35","rate":0.01,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"太平驾多保升级版（5座及以下）","productType":"驾意险","productDesc":"","planCode":"C05P156","planName":"太平驾多保升级版（5座及以下）","discount":"","maxQuantity":"1","unitAmount":"3534500","premium":"688","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"600000","premium":"243","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"100000","premium":"100","rate":0,"argc":[]},{"subName":"驾乘意外住院津贴","subCode":"ZR000311","amount":"18000","premium":"40","rate":0,"argc":[]},{"subName":"节假日意外伤害保险加倍","subCode":"ZR005930","amount":"600000","premium":"80","rate":0,"argc":[]},{"subName":"房屋-火灾、爆炸损失","subCode":"ZR005950","amount":"2000000","premium":"118","rate":0,"argc":[]},{"subName":"室内装潢及室内附属设施-火灾、爆炸损失","subCode":"ZR005951","amount":"200000","premium":"44","rate":0,"argc":[]},{"subName":"个人出行不便责任","subCode":"ZR005478","amount":"1500","premium":"6","rate":0,"argc":[]},{"subName":"拦车抢劫财物损失","subCode":"ZR005468","amount":"10000","premium":"14","rate":0,"argc":[]},{"subName":"个人行李损失责任","subCode":"ZR005920","amount":"5000","premium":"43","rate":0.01,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"E驾太平B款","productType":"驾意险","productDesc":"","planCode":"C05P003","planName":"E驾太平B款","discount":"","maxQuantity":"1","unitAmount":"1351000","premium":"399","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"1000000","premium":"190","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"150000","premium":"80","rate":0,"argc":[]},{"subName":"交通意外重大损伤","subCode":"ZR005415","amount":"200000","premium":"120","rate":0,"argc":[]},{"subName":"意外伤害救护车费用","subCode":"ZR000116","amount":"1000","premium":"9","rate":0.01,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"E驾太平C款","productType":"驾意险","productDesc":"","planCode":"C05P004","planName":"E驾太平C款","discount":"","maxQuantity":"1","unitAmount":"2052000","premium":"599","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"1500000","premium":"250","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"250000","premium":"120","rate":0,"argc":[]},{"subName":"交通意外重大损伤","subCode":"ZR005415","amount":"300000","premium":"210","rate":0,"argc":[]},{"subName":"意外伤害救护车费用","subCode":"ZR000116","amount":"2000","premium":"19","rate":0.01,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"E驾太平D款","productType":"驾意险","productDesc":"","planCode":"C05P005","planName":"E驾太平D款","discount":"","maxQuantity":"1","unitAmount":"3310000","premium":"1099","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"2500000","premium":"460","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"300000","premium":"150","rate":0,"argc":[]},{"subName":"交通意外重大损伤","subCode":"ZR005415","amount":"500000","premium":"450","rate":0,"argc":[]},{"subName":"意外伤害救护车费用","subCode":"ZR000116","amount":"10000","premium":"39","rate":0,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"安心出行普通版B款","productType":"驾意险","productDesc":"","planCode":"C05P134","planName":"安心出行普通版B款","discount":"","maxQuantity":"1","unitAmount":"1290800","premium":"288","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"200000","premium":"55","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"200000","premium":"106","rate":0,"argc":[]},{"subName":"驾乘意外住院津贴","subCode":"ZR000311","amount":"10800","premium":"5","rate":0,"argc":[]},{"subName":"房屋-火灾、爆炸损失","subCode":"ZR005950","amount":"800000","premium":"67","rate":0,"argc":[]},{"subName":"室内装潢及室内附属设施-火灾、爆炸损失","subCode":"ZR005951","amount":"80000","premium":"55","rate":0,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"安心出行普通版C款","productType":"驾意险","productDesc":"","planCode":"C05P135","planName":"安心出行普通版C款","discount":"","maxQuantity":"1","unitAmount":"1718000","premium":"338","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"300000","premium":"87","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"300000","premium":"139","rate":0,"argc":[]},{"subName":"驾乘意外住院津贴","subCode":"ZR000311","amount":"18000","premium":"8","rate":0,"argc":[]},{"subName":"房屋-火灾、爆炸损失","subCode":"ZR005950","amount":"1000000","premium":"57","rate":0,"argc":[]},{"subName":"室内装潢及室内附属设施-火灾、爆炸损失","subCode":"ZR005951","amount":"100000","premium":"47","rate":0,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"安心出行普通版D款","productType":"驾意险","productDesc":"","planCode":"C05P136","planName":"安心出行普通版D款","discount":"","maxQuantity":"1","unitAmount":"2277000","premium":"388","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"300000","premium":"87","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"300000","premium":"139","rate":0,"argc":[]},{"subName":"驾乘意外住院津贴","subCode":"ZR000311","amount":"27000","premium":"12","rate":0,"argc":[]},{"subName":"房屋-火灾、爆炸损失","subCode":"ZR005950","amount":"1500000","premium":"83","rate":0,"argc":[]},{"subName":"室内装潢及室内附属设施-火灾、爆炸损失","subCode":"ZR005951","amount":"150000","premium":"67","rate":0,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"安心出行普通版E款","productType":"驾意险","productDesc":"","planCode":"C05P138","planName":"安心出行普通版E款","discount":"","maxQuantity":"1","unitAmount":"3236000","premium":"588","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"500000","premium":"145","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"500000","premium":"165","rate":0,"argc":[]},{"subName":"驾乘意外住院津贴","subCode":"ZR000311","amount":"36000","premium":"17","rate":0,"argc":[]},{"subName":"房屋-火灾、爆炸损失","subCode":"ZR005950","amount":"2000000","premium":"144","rate":0,"argc":[]},{"subName":"室内装潢及室内附属设施-火灾、爆炸损失","subCode":"ZR005951","amount":"200000","premium":"117","rate":0,"argc":[]}],"argc":{"riskcode":"C05"}}]';
    private $seat7 = '[{"productCode":"C05","productName":"E驾太平B款","productType":"驾意险","productDesc":"","planCode":"C05P003","planName":"E驾太平B款","discount":"","maxQuantity":"1","unitAmount":"1351000","premium":"399","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"1000000","premium":"190","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"150000","premium":"80","rate":0,"argc":[]},{"subName":"交通意外重大损伤","subCode":"ZR005415","amount":"200000","premium":"120","rate":0,"argc":[]},{"subName":"意外伤害救护车费用","subCode":"ZR000116","amount":"1000","premium":"9","rate":0.01,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"E驾太平C款","productType":"驾意险","productDesc":"","planCode":"C05P004","planName":"E驾太平C款","discount":"","maxQuantity":"1","unitAmount":"2052000","premium":"599","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"1500000","premium":"250","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"250000","premium":"120","rate":0,"argc":[]},{"subName":"交通意外重大损伤","subCode":"ZR005415","amount":"300000","premium":"210","rate":0,"argc":[]},{"subName":"意外伤害救护车费用","subCode":"ZR000116","amount":"2000","premium":"19","rate":0.01,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"E驾太平D款","productType":"驾意险","productDesc":"","planCode":"C05P005","planName":"E驾太平D款","discount":"","maxQuantity":"1","unitAmount":"3310000","premium":"1099","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"2500000","premium":"460","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"300000","premium":"150","rate":0,"argc":[]},{"subName":"交通意外重大损伤","subCode":"ZR005415","amount":"500000","premium":"450","rate":0,"argc":[]},{"subName":"意外伤害救护车费用","subCode":"ZR000116","amount":"10000","premium":"39","rate":0,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"太平驾多保体验版（6-7座）","productType":"驾意险","productDesc":"","planCode":"C05P151","planName":"太平驾多保体验版（6-7座）","discount":"","maxQuantity":"1","unitAmount":"1558200","premium":"368","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"200000","premium":"89","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"50000","premium":"64","rate":0,"argc":[]},{"subName":"驾乘意外住院津贴","subCode":"ZR000311","amount":"5400","premium":"20","rate":0,"argc":[]},{"subName":"节假日意外伤害保险加倍","subCode":"ZR005930","amount":"200000","premium":"51","rate":0,"argc":[]},{"subName":"个人行李损失责任","subCode":"ZR005920","amount":"2000","premium":"36","rate":0.02,"argc":[]},{"subName":"房屋-火灾、爆炸损失","subCode":"ZR005950","amount":"1000000","premium":"79","rate":0,"argc":[]},{"subName":"室内装潢及室内附属设施-火灾、爆炸损失","subCode":"ZR005951","amount":"100000","premium":"26","rate":0,"argc":[]},{"subName":"个人出行不便责任","subCode":"ZR005478","amount":"800","premium":"3","rate":0,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"太平驾多保基础版（6-7座）","productType":"驾意险","productDesc":"","planCode":"C05P154","planName":"太平驾多保基础版（6-7座）","discount":"","maxQuantity":"1","unitAmount":"1818000","premium":"468","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"300000","premium":"119","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"100000","premium":"100","rate":0,"argc":[]},{"subName":"驾乘意外住院津贴","subCode":"ZR000311","amount":"9000","premium":"34","rate":0,"argc":[]},{"subName":"节假日意外伤害保险加倍","subCode":"ZR005930","amount":"300000","premium":"58","rate":0,"argc":[]},{"subName":"房屋-火灾、爆炸损失","subCode":"ZR005950","amount":"1000000","premium":"79","rate":0,"argc":[]},{"subName":"室内装潢及室内附属设施-火灾、爆炸损失","subCode":"ZR005951","amount":"100000","premium":"26","rate":0,"argc":[]},{"subName":"个人出行不便责任","subCode":"ZR005478","amount":"1000","premium":"4","rate":0,"argc":[]},{"subName":"拦车抢劫财物损失","subCode":"ZR005468","amount":"5000","premium":"8","rate":0,"argc":[]},{"subName":"个人行李损失责任","subCode":"ZR005920","amount":"3000","premium":"40","rate":0.01,"argc":[]}],"argc":{"riskcode":"C05"}},{"productCode":"C05","productName":"太平驾多保升级版（6-7座）","productType":"驾意险","productDesc":"","planCode":"C05P157","planName":"太平驾多保升级版（6-7座）","discount":"","maxQuantity":"1","unitAmount":"3534500","premium":"788","insuredNum":"1","subCoverage":[{"subName":"驾乘意外身故、伤残","subCode":"ZR000309","amount":"600000","premium":"278","rate":0,"argc":[]},{"subName":"驾乘意外医疗费用","subCode":"ZR000310","amount":"100000","premium":"115","rate":0,"argc":[]},{"subName":"驾乘意外住院津贴","subCode":"ZR000311","amount":"18000","premium":"45","rate":0,"argc":[]},{"subName":"节假日意外伤害保险加倍","subCode":"ZR005930","amount":"600000","premium":"91","rate":0,"argc":[]},{"subName":"房屋-火灾、爆炸损失","subCode":"ZR005950","amount":"2000000","premium":"147","rate":0,"argc":[]},{"subName":"室内装潢及室内附属设施-火灾、爆炸损失","subCode":"ZR005951","amount":"200000","premium":"40","rate":0,"argc":[]},{"subName":"个人出行不便责任","subCode":"ZR005478","amount":"1500","premium":"6","rate":0,"argc":[]},{"subName":"拦车抢劫财物损失","subCode":"ZR005468","amount":"10000","premium":"16","rate":0,"argc":[]},{"subName":"个人行李损失责任","subCode":"ZR005920","amount":"5000","premium":"50","rate":0.01,"argc":[]}],"argc":{"riskcode":"C05"}}]';

    public $seat = '';

    public $productCodeList = [];

    public $printer = NonCarProductListPrinter::class;
    public function printerInit(): Response
    {
        $body = $this->getBody();
        $productList = $body['body']['fcProduct'] ?? [];
        $riskList = [];
        $printer = $this->printer;
        foreach ($productList as $key => $val){
            if(strpos($val['productName'],'E驾太平') !== false){
                $riskList[] = $val;
            }
            if(strpos($val['productName'],'太平驾多保') !== false){
                $riskList[] = $val;
            }
            if(strpos($val['productName'],'安心出行') !== false){
                $riskList[] = $val;
            }
        }

        $kindList = $body['body']['fcKind'] ?? [];
        if(!empty($kindList)){
            $fcKind = [];
            foreach ($kindList as $val){
                $fcKind[$val['productId']][] = $val;
            }
            foreach ($riskList as &$value){
                $value['coverageList'] = $fcKind[$value['productId']];
            }

            foreach ($riskList as $item) {
                $amount = $premium = '0';
                $productPrinter = new NonCarProductPrinter();
                $productPrinter->productCode = $item['productCode'] ?? '';//产品编码
                $this->productCodeList[] = $productPrinter->productCode;
                $productPrinter->productName = $item['productName'] ?? '';//产品名称
                $productPrinter->productType = '驾意险';
                $productPrinter->productDesc = '';
                $productPrinter->planCode    = $item['projectCode'] ?? '';//方案代码
                $productPrinter->planName    = $item['productName'] ?? '';//方案名称
                $productPrinter->maxQuantity = $item['quantity'];//最大购买份数
                $productPrinter->argc['riskcode'] = $item['riskcode'] ?? '';//险种代码

                foreach ($item['coverageList'] ?? [] as $sub) {
                    $subCoverage = new NonCarSubCoveragePrinter();
                    $subCoverage->subCode = $sub['kindCode'] ?? '';
                    $subCoverage->subName = $sub['kindName'] ?? '';
                    $subCoverage->amount  = $sub['insured'] ?? '';
                    $subCoverage->premium = $sub['premium'] ?? '0';
                    $subCoverage->rate    = round($sub['premium'] / $sub['insured'],2);

                    $amount  += $subCoverage->amount;
                    $premium += $subCoverage->premium;

                    $productPrinter->subCoverageAppend($subCoverage);
                }
                $productPrinter->unitAmount = (string)$amount;
                $productPrinter->premium    = (string)$premium;
                $printer->productListAppend($productPrinter);
            }
            $this->printer = $printer;
        }

    return $this;

    }

    public function staticList()
    {
        $printer = new $this->printer;
        if($this->seat){
            $riskList = [];
            if($this->seat <= 5){
                $riskList = json_decode($this->seat5,true);
            }elseif($this->seat <= 7){
                $riskList = json_decode($this->seat7,true);
            }
            foreach ($riskList as $item) {
                $amount = $premium = '0';
                $productPrinter = new NonCarProductPrinter();
                $productPrinter->productCode = $item['productCode'] ?? '';//产品编码
                $this->productCodeList[] = $productPrinter->productCode;
                $productPrinter->productName = $item['productName'] ?? '';//产品名称
                $productPrinter->productType = '驾意险';
                $productPrinter->planCode    = $item['planCode'] ?? '';//方案代码
                $productPrinter->planName    = $item['planName'] ?? '';//方案名称
                $productPrinter->maxQuantity = $item['maxQuantity'];//最大购买份数
                $productPrinter->argc['riskcode'] = $item['argc']['riskcode'] ?? '';//险种代码
                $productPrinter->argc['productName'] = $productPrinter->productName;
                foreach ($item['subCoverage'] ?? [] as $sub) {
                    $subCoverage = new NonCarSubCoveragePrinter();
                    $subCoverage->subCode = $sub['subCode'] ?? '';
                    $subCoverage->subName = $sub['subName'] ?? '';
                    $subCoverage->amount  = $sub['amount'] ?? '';
                    $subCoverage->premium = $sub['premium'] ?? '0';
                    $subCoverage->rate    = $sub['rate'] ?? 0;

                    $productPrinter->subCoverageAppend($subCoverage);
                }
                $productPrinter->unitAmount = $item['unitAmount'] ?? '';
                $productPrinter->premium    = $item['premium'] ?? '';

                $printer->productListAppend($productPrinter);
            }
        }
        $this->printer = $printer;
    }
}
